<?php

namespace App\Http\Controllers\Api;

use App\Http\Controllers\Controller;
use App\Http\Server\RestockServer;
use App\Services\JsonResponseService;
use Illuminate\Http\Request;

class RestockController extends Controller
{
    //进货记录管理

    public function __construct() {
        $this->server = new RestockServer();
    }

    /**
     * 添加进货记录
     * @param Request $request
     */
    public function addRestock(Request $request){
        $id = $request->input('id');
        $goods_id = $request->input('goods_id');
        $manufacturer_id = $request->input('manufacturer_id');
        $cost_price = $request->input('cost_price');
        $total_price = $request->input('total_price');
        $num = $request->input('num');
        $now_date = $request->input('now_date');
        $res = $this->server->addRestockServer($id,$goods_id,$num,$now_date,$manufacturer_id,$cost_price,$total_price);
        return JsonResponseService::success($res['data'],$res['msg'],$res['status']);
    }

    /**
     * 获取进货记录
     */
    public function getRestockList(Request $request){
        // 获取查询条件
        $params = $request->only(['goods_id','manufacturer_id','now_date']);
        $per_page = $request->input('per_page');
        $res = $this->server->getRestockListServer($params,$per_page);
        return JsonResponseService::success($res['data'],$res['msg'],$res['status']);
    }
}
